<?php

namespace app\models;

use app\components\BaseActiveRecord;
use Yii;

/**
 * This is the model class for table "{{%comment}}".
 *
 * @property int $id
 * @property int $uid
 * @property int $type
 * @property int $parent_id
 * @property int $book_id
 * @property string $content 内容
 * @property int $like 赞
 * @property int $status
 * @property int $create_time
 */
class Comment extends BaseActiveRecord {

    const TYPE_BOOK = 1;
    const TYPE_REPORT = 2;

    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return '{{%comment}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['uid', 'type', 'parent_id', 'book_id', 'like', 'status', 'create_time'], 'integer'],
            [['content'], 'string', 'max' => 500],
            [['content'], 'required'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => Yii::t('app', 'ID'),
            'uid' => Yii::t('app', 'Uid'),
            'type' => Yii::t('app', 'Type'),
            'parent_id' => Yii::t('app', 'Parent ID'),
            'book_id' => Yii::t('app', 'Book ID'),
            'content' => Yii::t('app', 'Content'),
            'like' => Yii::t('app', 'Like'),
            'status' => Yii::t('app', 'Status'),
            'create_time' => Yii::t('app', 'Create Time'),
        ];
    }

    public function getUser() {
        return $this->hasOne(User::class, ['id' => 'uid']);
    }
}
